﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
namespace WPFExcelReport
{
    public partial class TSSD0561
    { 
        public TSSD0561()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return; 
            SDSA = "0561";  
            InitializeComponent(); 
        }
        public override void LOADALL()
        {
            base.LOADALL();
            foreach (DataRow row in TBMain.Rows)
            {
                row["SDES"] = Helpers.Helper.Convert8859P1ToGB2312(row["SDES"].ToString().Trim());
                row["DES"] = Helpers.Helper.Convert8859P1ToGB2312(row["DES"].ToString().Trim());
            }

        }
        public string GetColorNo()
        {
            if (dwKEY == null)
                return " ";
            string sv = dwKEY["VALUE"].ToString();
            if (sv.Trim() == "")
                sv = "0";
            string key = dwKEY["KEY"].ToString();
            string ColorNo = Helpers.Helper.Left((Convert.ToInt32(sv) + 1).ToString().PadRight(5), 5);
            dwKEY["VALUE"] = ColorNo;
            string data = dwKEY["SDDATEN"].ToString();
            dwKEY["SDDATEN"] = data.Substring(0, 69) + ColorNo + data.Substring(74, 77) + Helpers.Helper.Left(app.User.PadRight(8), 8) + Helpers.Helper.Left(INTEXDBC.GetDBDATE().PadRight(8), 8) + "0000*";
            dwData = ((VSDDAT)MV).SetData.Tables["SDDAT"].NewRow();
            dwData["SDSA"] = "0561";
            dwData["SDKEY"] = dwKEY["SDKEY"];
            dwData["SDDATEN"] = dwKEY["SDDATEN"];
            ((VSDDAT)MV).SaveSDDAT(dwData, app.company);
            string ID = dwKEY["SDES"].ToString().Trim();
            string CID = "";
            if (ID == "Y7")
            {
                CID = ID + ColorNo.Trim() + "U";
            }
            else
            {
                CID = ID + ColorNo;
            }
            return CID;
        }
    }
}
